/*
	Written by: Daniel Mathis
		Implements non-trivial class functions.
*/

#include "GameLogic.h"

LogicController::LogicController(ShipController &theSC, AsteroidController &theAC, BulletController &theBC)
: sc(theSC), ac(theAC), bc(theBC)
{}

bool LogicController::isCollision()
{
	// Examine each asteroid in the gameObject's list. Return true is there is a collision. That is,
	// if the ship is within the asteroid's bounding circle. Asteroid's circle defined by center, and radius = max(height, width)
	// Treat the ship as a circle, with radius = max(height, width)
	// 		Collision if ----- |center(asteroid) - center(ship) < radius(asteroid) + radius(ship)
	list<Asteroid*>::iterator it;
	
	for(it = ac.getAsteroidIterator(); it != ac.getAsteroidIteratorEnd(); ++it)
	{
			if(sqrtf(pow(sc.getShip()->itsXLoc() - (*it)->itsXLoc(), 2) + 
				 pow(sc.getShip()->itsYLoc() - (*it)->itsYLoc(), 2)) < 
			(sc.getShip()->itsRadius() + (*it)->itsRadius()))
				return true;
	}
	return false;
}
